#include <assert.h>
#include "scripttimeaction.h"
namespace timerlib
{
ScriptTimeAction::ScriptTimeAction(const std::string& aFileName, const std::string& aFuncName, int aIntrival) : ResideTimeAction(aIntrival)
{
    setScriptHandler(aFileName, aFuncName);
}

void ScriptTimeAction::setScriptFileName(const std::string& aFileName)
{
    m_scriptFileName = aFileName;
}

void ScriptTimeAction::setScriptFuncName(const std::string& aFuncname)
{
    m_scriptFuncName = aFuncname;
}

void ScriptTimeAction::setScriptHandler(const std::string& aFileName, const std::string& aFuncname)
{
    m_scriptFileName = aFileName;
    m_scriptFuncName = aFuncname;
}

void ScriptTimeAction::onCreate()
{

}

void    ScriptTimeAction::onArrivalTime()
{
    AlHelper::Callfunction(m_scriptFileName.c_str(), m_scriptFuncName.c_str());
}

//static    void    ScriptTimeActionFactory_Generic(asIScriptGeneric *gen)
//{
//    asIScriptEngine *engine = gen->GetEngine();
//    std::string *aFileName = (std::string *)gen->GetArgObject(0);
//    std::string *aFuncName = (std::string *)gen->GetArgObject(1);
//    asDWORD aIntrival = gen->GetArgDWord(2);

//    ScriptTimeAction* p  = new ScriptTimeAction(*aFileName, *aFuncName, aIntrival);
//    *(ScriptTimeAction**)gen->GetAddressOfReturnLocation() = p;
//}

//bool    ExportScriptTimeAction()
//{
//    int r;
//    r = AlHelper::RegisterObjectType("ScriptTimeAction", sizeof(timerlib::ScriptTimeAction), asOBJ_REF);
//    r = AlHelper::RegisterObjectBehaviour("ScriptTimeAction", asBEHAVE_FACTORY, "ScriptTimeAction@ f(const string &in, const string &in, uint)", asFUNCTION(ScriptTimeActionFactory_Generic), asCALL_GENERIC);

//    r = AlHelper::RegisterObjectBehaviour("ScriptTimeAction", asBEHAVE_ADDREF, "void f()", asMETHOD(ScriptTimeAction,AddRef), asCALL_THISCALL); assert( r >= 0 );
//    r = AlHelper::RegisterObjectBehaviour("ScriptTimeAction", asBEHAVE_RELEASE, "void f()", asMETHOD(ScriptTimeAction,Release), asCALL_THISCALL); assert( r >= 0 );

//    //r = AlHelper::RegisterObjectType("ScriptTimeAction", sizeof(timerlib::TimeAction), asOBJ_REF);

//    return r >= 0;
//}
}
